home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Paths Regions and Clipping / Clover / Clover.cs next >
Encoding:
Text File  |  2001-01-15  |  1.4 KB  |  42 lines

  1. //-------------------------------------
  2. // Clover.cs ⌐ 2001 by Charles Petzold
  3. //-------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Windows.Forms;
  8.  
  9. class Clover: PrintableForm
  10. {
  11.      public new static void Main()
  12.      {
  13.           Application.Run(new Clover());
  14.      }
  15.      public Clover()
  16.      {
  17.           Text = "Clover";
  18.      }
  19.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  20.      {
  21.           GraphicsPath path = new GraphicsPath();
  22.  
  23.           path.AddEllipse(0,      cy / 3, cx / 2, cy / 3);  // Left
  24.           path.AddEllipse(cx / 2, cy / 3, cx / 2, cy / 3);  // Right
  25.           path.AddEllipse(cx / 3, 0,      cx / 3, cy / 2);  // Top
  26.           path.AddEllipse(cx / 3, cy / 2, cx / 3, cy / 2);  // Bottom
  27.  
  28.           grfx.SetClip(path);
  29.           grfx.TranslateTransform(cx / 2, cy / 2);
  30.  
  31.           Pen   pen     = new Pen(clr);
  32.           float fRadius = (float) Math.Sqrt(Math.Pow(cx / 2, 2) + 
  33.                                             Math.Pow(cy / 2, 2));
  34.      
  35.           for (float fAngle = 0; fAngle <  (float) Math.PI * 2; 
  36.                                  fAngle += (float) Math.PI / 180)
  37.           {
  38.                grfx.DrawLine(pen, 0, 0, fRadius * (float) Math.Cos(fAngle),
  39.                                        -fRadius * (float) Math.Sin(fAngle));
  40.           }
  41.      }
  42. }